import api from '@/api/user'

// 获取对应界面信息
async function getPageData (page) {
  let id
  if (sessionStorage.getItem('_id')) {
    id = sessionStorage.getItem('_id')
  }
  sessionStorage['page'] = page
  try {
    const _page = page
    const res = await api.getAllData(id)
    // console.log(res)
    const { code, result } = res
    if (code == 200 && result) {
      return result[_page]
    }
  } catch (error) {
    // console.log(error)
  }
}

// 保留一位小数
function toDecimal (x) {
  var f = parseFloat(x)
  if (isNaN(f)) {
    return '0.0'
  }
  f = Math.round(x * 100) / 100
  var s = f.toString()
  var rs = s.indexOf('.')
  if (rs < 0) {
    rs = s.length
    s += '.'
  }
  while (s.length <= rs + 1) {
    s += '0'
  }
  return s
}

export {
  getPageData,
  toDecimal
}
